IF exists(SELECT * FROM dbo.sysobjects WHERE name='r_procent' AND xtype='FN') 
BEGIN
	DROP FUNCTION r_procent
END
GO

CREATE function r_procent(
@cijfer float,
@totaal float)
returns int
as
begin
  declare @res int
  if (@cijfer < 0) or (@totaal <=0)
	set @res = -1
	else 
	set @res = round((@cijfer*100 + 0.000001)/@totaal,0)
  return @res
end
----------